import { defineConfig, loadEnv } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import AutoImport from 'unplugin-auto-import/vite'

export default defineConfig(({ mode }) => {
	//拿到配置的环境变量
	const env = loadEnv(mode, process.cwd())
	return {
		plugins: [
		    uni(),		
		    AutoImport({
		      imports: [
		        // 需要自动导入的插件，自定义导入
		        'vue',
		        'vue-router',
		        'pinia',
		        /\.[tj]sx?$/,
		      ],
		      defaultExportByFilename: true,
		      dirs: [
		        './store',
		        './common'
		      ]
		    })
		  ],
		server: {
			proxy: {
				[env.VITE_BASE_URL]: {
					target: env.VITE_URL,
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/api/, ""),
				}
			},
		},
	}
})